Xbasic

Array first_empty Method

Syntax

dim Index as N = <array>.first_empty([C property])

Arguments

propertyCharacter

If specified, returns the index of the first property that that is undefined for an element in the array.

Returns

IndexNumeric

Returns the index of the first empty element in the array.

Description

Return the last unused entry in the array.

Discussion

The <array>.first_empty() method returns the index of the first empty element in an array.

Example

Assume an array "A" contains the following elements:

Element

Value

A[1]

Orange

A[2]

Banana

A[3]

Apple

A[4]

Pineapple

A[5]

Mango

A[6]

A[7]

A[8]

? A.first_empty() 
= 6 ' because element 6 is the first NULL (empty) element.

The following example demonstrates using the optional property parameter.

dim trs[10] as p
trs[1].city = "Boston"
trs[1].state = "MA"
trs[2].city = "Attleboro"
trs[2].state = "MA"
trs[3].city = "Providence"
trs[3].state = "RI"
trs[4].city = "Newport"
trs[4].state = ""
trs[5].city = "Barrington"
trs[5].state = ""

? trs.first_empty("state")
 = 4
If a property is not defined for an element in the array, it will be skipped. In the example above, if state had not been added to trs[4] and trs[5], <array>.first_empty() would return 6, not 4. Therefore, it is important that all elements in the array have the same properties defined.